package com.job.search.controller;

import com.job.client.common.result.ResponseResult;
import com.job.client.model.company.dto.CompanyEsDto;
import com.job.client.model.posts.dto.PostsEsDto;
import com.job.client.model.posts.pojo.Posts;
import com.job.search.dto.CompanySearchDto;
import com.job.search.dto.PostsSearchDto;
import com.job.search.service.SearchPostsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/api/v1/search/posts")
@RestController
@Api(tags = "职位搜索服务接口文档")
public class SearchPostsController {
    @Autowired
    private SearchPostsService postsService;
    @PostMapping("/add")
    @ApiOperation("根据id向posts插入数据")
    public ResponseResult addPosts(@RequestBody PostsEsDto posts){
        return postsService.addPosts(posts);
    }
    @PostMapping("/bulk/add")
    @ApiOperation("根据id批量向posts插入数据")
    public ResponseResult blkAddCompany(@RequestBody List<PostsEsDto> postsEsDtoList){
        return postsService.blkAddPosts(postsEsDtoList);
    }
    @GetMapping("/{postsId}")
    @ApiOperation("根据id查询posts")
    public ResponseResult getById(@PathVariable String postsId){
        return postsService.getById(postsId);
    }
    @DeleteMapping("/{postsId}")
    @ApiOperation("根据id删除posts中的数据")
    public ResponseResult deleteById(@PathVariable String postsId){
        return postsService.deleteById(postsId);
    }

    @PostMapping("/update")
    @ApiOperation("根据posts修改数据,null的数据自动跳过")
    public ResponseResult modifyPartialById(@RequestBody PostsEsDto posts){
        return postsService.modifyPartialById(posts);
    }

    @PostMapping("/search")
    @ApiOperation("关键字分词查询")
    public ResponseResult search(@RequestBody PostsSearchDto dto){
        return postsService.search(dto);
    }
    @PostMapping("/search/highlight")
    @ApiOperation("关键字分词查询，并把关键字高亮显示")
    public ResponseResult searchHighlight(@RequestBody PostsSearchDto dto){
        return postsService.searchHighlight(dto);
    }
}
